/**
 * 
 */

/**
 * @author John Sterken, Rudie Rep
 * @version 20120912
 */
public class Crypto {
	/**
	 * 
	 * @param text
	 * @param offset
	 * @param action if true >> encrypt else decrypt
	 * @return
	 */
	 public String crypt(String text, int offset, boolean action) {
	 		StringBuilder cryptedText = new StringBuilder(text.toLowerCase());
			char newChar2= ' ';
			int newChar = 0;
			for(int i=0;i < text.length(); i++) {
				if(cryptedText.charAt(i) >= 'a' && cryptedText.charAt(i) <= 'z') {
					if(action){
						newChar = cryptedText.charAt(i) + offset;
						
						if(newChar > 'z'){ 
							newChar = newChar - 'z';
							newChar = newChar + '`';
						}
					}
					else{
						newChar = cryptedText.charAt(i) - offset;
						
						if(newChar < 'a'){ 
							newChar = newChar - 'a';
							newChar = newChar + '{';
						}
					}
					newChar2 = (char) newChar;
					
					cryptedText.setCharAt(i, newChar2);
				}
			}
			return cryptedText.toString();
	 }
}
	 
	 
	 /*public String decrypt(String text, int offset) {
			StringBuilder decryptedText = new StringBuilder(text.toLowerCase());
			char newChar2= ' ';
			for(int i=0;i < text.length(); i++) {
				if(decryptedText.charAt(i) >= 'a' && decryptedText.charAt(i) <= 'z') {
					int newChar = decryptedText.charAt(i) - offset;
					
					if(newChar < 'a'){ 
						newChar = newChar - 'a';
						newChar = newChar + '{';
					}
					
					newChar2 = (char) newChar;
					
					decryptedText.setCharAt(i, newChar2);
				}
			}
			return decryptedText.toString();
		 }
	 
}*/
